import { createStore } from 'vuex'
import menu from './modules/menu'
import role from './modules/role'
import user from './modules/user'

export default createStore({
  state: {
    userInfo:sessionStorage.getItem('userinfo') ? JSON.parse(sessionStorage.getItem('userinfo') as any) : null
  },
  getters: {
    getUser(state){
      return state.userInfo
    }
  },
  mutations: {
    REQ_USERINFO(state,payload){
      if(payload){
        state.userInfo = payload
        // 把结果存储到绘画存储
        sessionStorage.setItem('userinfo',JSON.stringify(payload))
      }else{
        sessionStorage.removeItem('userinfo')
        state.userInfo = null
      }
    }
  },
  actions: {
    changeUserInfo({commit},payload){
      commit('REQ_USERINFO',payload)
    }
  },
  modules: {
    menu,role,user
  }
})
